#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   2.py
@Time    :   2020/05/24 11:08:19
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# Start typing your code from here
# 编写一个装饰器，能记录其他函数调用的日志，将日志写入到文件中

import logging
from datetime import datetime

LOG_FORMART = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.DEBUG,
                    format=LOG_FORMART,
                    filename="homework5/my.log",
                    filemode='a')
# logging.debug("this is debug")
# logging.info("this is info")
# logging.warning("this is warning")
# logging.error("this is error")
# logging.critical("this is critical")  #配置logger


def log(text):
    def decorator(func):
        def wrapper(*args, **kw):

            logging.debug(text)
            print('call %s():' % func.__name__)
            return func(*args, **kw)

        return wrapper

    return decorator


@log("test done")
def now():
    print(datetime.now())


def main():
    now()


if __name__ == "__main__":
    main()